import akshare as ak
import pandas as pd
from core.crawl import crawl_data
from core.indicator import dispose_data
from core.display import draw_data
from core.strategy import execute_strategy

# fund_etf_hist_em_df = ak.fund_etf_hist_em(symbol='513130', period='weekly', start_date='20250910',
#                                           end_date='20251102', adjust="hfq")
# print(fund_etf_hist_em_df)
# exit()


# 爬取数据
# crawl_data()

# 计算指标
# dispose_data()

# 执行策略
execute_strategy()

# 画K线图
# draw_data()

exit()
# symbol_list = ['399330', '399850', '100016', '100132', '100698', '100688']
# period_list = ['daily', 'weekly', 'monthly']
# for symbol in symbol_list:
#     for period in period_list:
#         index_zh_a_hist_df = ak.index_zh_a_hist(symbol=symbol, period=period, start_date="19700101", end_date="22220101")
#         index_zh_a_hist_df.to_excel(f"./{symbol}_{period}.xlsx")

# exit()

# 获取基金列表
# fund_name_em_df = ak.fund_name_em()
# fund_name_em_df.to_excel(f"./天天基金列表.xlsx")

# 获取基金历史数据
symbol_list = ['510080', '270044', '400030', '006549', '007744', '003376', '006961', '003358', '004042', '161119', '003547', '217022']
for symbol in symbol_list:
    fund_open_fund_info_em_df = ak.fund_open_fund_info_em(symbol=symbol, indicator="累计净值走势", period="成立来")
    fund_open_fund_info_em_df.to_excel(f"./data/原始数据/纯债/{symbol}_l.xlsx")
symbol_list = ['002276', '360008', '005908', '217024', '110035', '161115', '110017', '110018']
for symbol in symbol_list:
    fund_open_fund_info_em_df = ak.fund_open_fund_info_em(symbol=symbol, indicator="累计净值走势", period="成立来")
    fund_open_fund_info_em_df.to_excel(f"./data/原始数据/积极债/{symbol}_l.xlsx")
exit()

# 获取fund列表
# fund_name_em_df = ak.fund_name_em()
# fund_name_em_df.to_excel('./fund.xlsx')

# lof_list = [
#     {'symbol': '161119', 'start_date': '20130109'},
#     {'symbol': '161716', 'start_date': '20150316'},
# ]
# for period in ['daily', 'weekly', 'monthly']:
#     for lof in lof_list:
#         fund_lof_hist_em_df = ak.fund_lof_hist_em(symbol=lof.get('symbol'), period=period,
#                                                   start_date=lof.get('start_date'), adjust='')
#
#         fund_lof_hist_em_df.to_excel(f"./{lof.get('symbol')}_{period}.xlsx")

# fund_etf_category_sina_df = ak.fund_etf_category_sina()
# fund_etf_category_sina_df.to_excel('fund.xlsx')

# symbol_list = ['sz161119', 'sh110035', 'sz161115', 'sh110017', 'sh110018']
# for symbol in symbol_list:
#     fund_etf_hist_sina_df = ak.fund_etf_hist_sina(symbol=symbol)
#     fund_etf_hist_sina_df.to_excel(f"./{symbol}.xlsx")

fund_list = ['217024', '217022', '003547',  '003358', '006961', '003376']

for symbol in fund_list:
    fund_open_fund_info_em_df = ak.fund_open_fund_info_em(symbol=symbol, indicator="单位净值走势")
    fund_open_fund_info_em_df.to_excel(f"./{symbol}.xlsx")

